package com.cykj.handler;

import com.cykj.entity.GoodsEntity;
import com.cykj.entity.PageEntity;
import com.cykj.service.indexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class HomeHandler {
    @Autowired
    private indexService indexService;

    @RequestMapping("/Home")
    public Map<String,Object> home(HttpServletRequest req){

        String pageStr = req.getParameter("currentPage");
        String recPerPageStr = req.getParameter("pageCount");

        int page = Integer.parseInt(pageStr);
        int recPerPage= 4;
        int counts = indexService.selCount();
        int pageCount = counts%recPerPage==0 ? (counts/recPerPage) :(counts/recPerPage)+1;

        List<GoodsEntity> list = indexService.selTblgoods((page-1)*recPerPage,recPerPage);
        Map<String,Object> map = new HashMap<String,Object>();
        PageEntity pageBean = new PageEntity();
//        pageBean.setPage(page);
//        pageBean.setPageCount(pageCount);
//        map.put("page",pageBean);
//        map.put("data",list);

        return map;
    }
}
